package com.ruoyi.yljf.controller.AppController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yljf.domain.ActiveOther;
import com.ruoyi.yljf.domain.Table;
import com.ruoyi.yljf.domain.dto.ActiveArticleDTO;
import com.ruoyi.yljf.domain.dto.ActiveOtherDTO;
import com.ruoyi.yljf.domain.dto.ActiveUserDTO;
import com.ruoyi.yljf.domain.dto.TableVO;
import com.ruoyi.yljf.domain.enums.yljfEnums;
import com.ruoyi.yljf.domain.vo.ActiveArticleVO;
import com.ruoyi.yljf.domain.vo.ActiveOtherVO;
import com.ruoyi.yljf.domain.vo.ActiveUserVO;
import com.ruoyi.yljf.service.IActiveOtherService;
import com.ruoyi.yljf.service.IArticleTableService;
import com.ruoyi.yljf.service.TableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 活动绑定信息表Controller
 * 
 * @author metaee
 * @date 2025-02-13
 */
@RestController
@RequestMapping("api/other")
public class ApiActiveOtherController extends BaseController {
    @Autowired
    private IActiveOtherService activeOtherService;
    @Autowired
    private TableService tableService;

    /**
     * 获取活动相关绑定信息
     */
    @Anonymous
    @GetMapping(value = "/getActivitySpace")
    public TableDataInfo getActivitySpace(ActiveOtherDTO activeOtherDTO) {
        startPage();
        ActiveOther activeOther = new ActiveOther(activeOtherDTO.getActiveId(), null, activeOtherDTO.getType(),activeOtherDTO.getSearchText());
        List<ActiveOther> list = activeOtherService.selectActiveOtherList(activeOther);
        List<?> listVO = activeOtherService.getArticleSpace(list, activeOtherDTO);
        return getDataTableInfo(listVO,list);
//        return getDataTable(listVO);
    }

    /**
     * 用户发布文章
     */
    @PostMapping(value = "/addActiveArticle")
    @Transactional
    public AjaxResult addActiveArticle(@RequestBody ActiveArticleDTO activeArticleDTO) {
        activeOtherService.addActiveArticle(activeArticleDTO);
        return success();
    }

    /**
     * 用户活动报名
     */
    @PostMapping(value = "/addActiveUser")
    public AjaxResult addActiveUser(@RequestBody ActiveUserDTO activeUserDTO) {
        return activeOtherService.addActiveUser(activeUserDTO);
    }

    /**
     * 查询标签管理列表
     */
    @GetMapping("/tableList")
    @Anonymous
    public AjaxResult tableList(TableVO vo) {
        List<Table> list = tableService.queryTableList(vo);
        return success(list);
    }




}
